#include<reg51.h>
typedef unsigned int uint;	 //???????????
typedef unsigned char uchar;
 
uchar led[] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar led1[] = {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
uchar second; //??
uchar key; //????
uint t; //????,?500,??0.1s
 
sbit keyif = P3^7;	//????
void delay(){ //????,??????
	uchar i,j;
	for(i=0;i<255;i++){
		for(j=0;j<100;j++);
	}
}
 
void init(void) //???
{
	TMOD = 0x01;  //0000 0010 ?????
	second = 0; //??????0
	EA = 1;	 //???,???0????
	ET0 = 1;  //?????0??
	key = 0; //????????0
	t = 0; //??????0
}
 
void main(){
	init();
	P0 = led1[second/10];
	P2 = led[second%10];
	while(1){
		if(keyif == 0){
			delay();//????	 
			if(keyif == 0){		  
				key++;
			switch(key){
				   case 1: //???,?????
				   		TH0 =  0xee;
						TL0 = 0x00;
						TR0 = 1;			   		
				   		break;
				   case 2:	//???,?????
				   		t = 0; 
				   		TR0 = 0;
				   		break;
				   case 3: //???,????,????
				   		key = 0;
						second = 0;
						P0 = led1[0];
						P2 = led[0];
				   		break;
					}
				while(keyif == 0);  //?????,????			
			}
		}
	}
}
 
void timer() interrupt 1
{
	TR0 = 0; //????
	t++;
	if(t ==20){
		second++;
		P0 = led1[second/10];
		P2 = led[second%10];
		t = 0;
	}
	if(second == 99){ //????9.9?,??????
		second = 0;
		key = 2; //?????????
	}
	TR0 = 1; //???????		
}